/*
 * Copyright 2008 [rapid-framework], Inc. All rights reserved.
 * Website: http://www.rapid-framework.org.cn
 */

    define("pages/jls_Wpjs/main", [
            "../../plugins/easyui/jquery-easyui-1.5.1/jquery.easyui.min",
            "../../plugins/easyui/jquery-easyui-1.5.1/easyloader",
            "../../plugins/artTemplate/artTemplate",
            "../../common/tools",
            "../../common/componts",
            "../../common/kss",
            "../../pages/jls_Wpjs/form",
            "../../pages/jls_Jbxx/JbxxShowHide.html.js",
            "../../pages/jls_Wpjs/WpjsShowHide.html.js"
        ],
        function(require) {
            var comonts=require("../../common/componts");
            var wpjsForm=require("../../pages/jls_Wpjs/form");
            var tmp=require("../../pages/jls_Jbxx/JbxxShowHide.html");
            var tmpWpjs=require("../../pages/jls_Wpjs/WpjsShowHide.html");
            var kss=require("../../common/kss");
            var ryjbxxId="jbxxId";
            var wpjsId="wpjsId";
            var wpjs="wpjs";
            var selectid;
            var id;
            var jbxx="jbxx";

            var tableInit=function(){
                kss.initJbxxTable(ryjbxxId,{
                    singleSelect:true,
                    url:'/jls_jbxx/jbxxList',
                    detailFormatter : function(index, rowData) {
                        return '<table  style="height:60px;width:100%"><tr><td>户籍地详细地址：'
                            + (rowData.hjszd == null ? ""
                                : rowData.hjszd)
                            + '</td></tr><tr><td>现住地详细地址:'
                            + (rowData.xzd == null ? "" : rowData.xzd)
                            + '</td></tr><tr><td>办案单位:'
                            + (rowData.badw == null ? "" : rowData.badw)
                            + '</td></tr><tr><td>简要案情:'
                            + (rowData.aq == null ? "" : rowData.aq)
                            + '</td></tr></table>'
                    },
                    onDblClickRow:function(rowIndex, rowData){
                        if (rowData.rybh != undefined) {
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            $("#"+ryjbxxId).datagrid("selectRow", rowIndex);
                            var jbxx=$("#"+ryjbxxId).datagrid('getSelected');
                            wpjsForm.show(jbxx,{},refreshTable);

                            $('input').next().find('input[type=text]').css('background-color','#EBEBE4');
                            var myDate = new Date();
                            var str=myDate.toLocaleTimeString();
                        }
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(selectid!=rowData.id){
                            $("input[name='ryRadio']")[rowIndex].checked = true;
                            selectid=rowData.id;
                        }else{
                            $("#"+ryjbxxId).datagrid("unselectRow",rowIndex);
                            $("input[name='ryRadio']")[rowIndex].checked = false;
                            $('#'+ryjbxxId).datagrid('clearSelections');
                            selectid="";
                        }
                    },
                    onSelect:function(rowIndex, rowData){
                        var jbxx = $('#'+ryjbxxId).datagrid('getSelected');
                        var flag = $("input[name='ryRadio']")[rowIndex].checked;
                        if(jbxx && !flag){
                            var rybh = jbxx.rybh;
                            $('#'+wpjsId).datagrid('loadData', { total: 0, rows: [] });
                            if (rybh != undefined) {
                                var opts = $("#"+wpjsId).datagrid("options");
                                $("#"+wpjsId).datagrid("clearSelections");
                                $('#'+wpjsId).datagrid('load',{
                                    'rybh': rybh,
                                });
                            }
                        }else {
                            $('#'+wpjsId).datagrid('loadData', { total: 0, rows: [] });
                        }
                    },
                    rightmenu:function(){
                    }

                });
                comonts.initTable(wpjsId,{
                    title: 'Wpjs',
                    url:"/jls_wpjs/wpjsList",
                    columns:[                    	
                        {field: 'id',title: 'id',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="idRadio" id="idRadio"' + rowIndex + 'value="' + rowData.id + '" />';}},
                        {field: 'jsbh',title: 'jsbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jsbhRadio" id="jsbhRadio"' + rowIndex + 'value="' + rowData.jsbh + '" />';}},
                        {field: 'rybh',title: 'rybh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="rybhRadio" id="rybhRadio"' + rowIndex + 'value="' + rowData.rybh + '" />';}},
                        {field: 'jscxbh',title: 'jscxbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jscxbhRadio" id="jscxbhRadio"' + rowIndex + 'value="' + rowData.jscxbh + '" />';}},
                        {field: 'mc',title: 'mc',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="mcRadio" id="mcRadio"' + rowIndex + 'value="' + rowData.mc + '" />';}},
                        {field: 'lqr',title: 'lqr',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="lqrRadio" id="lqrRadio"' + rowIndex + 'value="' + rowData.lqr + '" />';}},
                        {field: 'xjcd',title: 'xjcd',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="xjcdRadio" id="xjcdRadio"' + rowIndex + 'value="' + rowData.xjcd + '" />';}},
                        {field: 'wplx',title: 'wplx',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="wplxRadio" id="wplxRadio"' + rowIndex + 'value="' + rowData.wplx + '" />';}},
                        {field: 'ys',title: 'ys',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="ysRadio" id="ysRadio"' + rowIndex + 'value="' + rowData.ys + '" />';}},
                        {field: 'dw',title: 'dw',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="dwRadio" id="dwRadio"' + rowIndex + 'value="' + rowData.dw + '" />';}},
                        {field: 'sl',title: 'sl',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="slRadio" id="slRadio"' + rowIndex + 'value="' + rowData.sl + '" />';}},
                        {field: 'djrq',title: 'djrq',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="djrqRadio" id="djrqRadio"' + rowIndex + 'value="' + rowData.djrq + '" />';}},
                        {field: 'djr',title: 'djr',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="djrRadio" id="djrRadio"' + rowIndex + 'value="' + rowData.djr + '" />';}},
                        {field: 'lqrq',title: 'lqrq',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="lqrqRadio" id="lqrqRadio"' + rowIndex + 'value="' + rowData.lqrq + '" />';}},
                        {field: 'lqzt',title: 'lqzt',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="lqztRadio" id="lqztRadio"' + rowIndex + 'value="' + rowData.lqzt + '" />';}},
                        {field: 'bz',title: 'bz',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="bzRadio" id="bzRadio"' + rowIndex + 'value="' + rowData.bz + '" />';}},
                        {field: 'wbwpbh',title: 'wbwpbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="wbwpbhRadio" id="wbwpbhRadio"' + rowIndex + 'value="' + rowData.wbwpbh + '" />';}},
                        {field: 'jjrxm',title: 'jjrxm',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jjrxmRadio" id="jjrxmRadio"' + rowIndex + 'value="' + rowData.jjrxm + '" />';}},
                        {field: 'jjrzjlx',title: 'jjrzjlx',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jjrzjlxRadio" id="jjrzjlxRadio"' + rowIndex + 'value="' + rowData.jjrzjlx + '" />';}},
                        {field: 'jjrzjh',title: 'jjrzjh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jjrzjhRadio" id="jjrzjhRadio"' + rowIndex + 'value="' + rowData.jjrzjh + '" />';}},
                        {field: 'jjrlxdh',title: 'jjrlxdh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jjrlxdhRadio" id="jjrlxdhRadio"' + rowIndex + 'value="' + rowData.jjrlxdh + '" />';}},
                        {field: 'jjrlxdz',title: 'jjrlxdz',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jjrlxdzRadio" id="jjrlxdzRadio"' + rowIndex + 'value="' + rowData.jjrlxdz + '" />';}},
                        {field: 'ybjjrgx',title: 'ybjjrgx',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="ybjjrgxRadio" id="ybjjrgxRadio"' + rowIndex + 'value="' + rowData.ybjjrgx + '" />';}},
                        {field: 'rsqsfyjb',title: 'rsqsfyjb',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="rsqsfyjbRadio" id="rsqsfyjbRadio"' + rowIndex + 'value="' + rowData.rsqsfyjb + '" />';}},
                        {field: 'rsqjbxxqk',title: 'rsqjbxxqk',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="rsqjbxxqkRadio" id="rsqjbxxqkRadio"' + rowIndex + 'value="' + rowData.rsqjbxxqk + '" />';}},
                        {field: 'sfyjzbs',title: 'sfyjzbs',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="sfyjzbsRadio" id="sfyjzbsRadio"' + rowIndex + 'value="' + rowData.sfyjzbs + '" />';}},
                        {field: 'jzbsxxqk',title: 'jzbsxxqk',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jzbsxxqkRadio" id="jzbsxxqkRadio"' + rowIndex + 'value="' + rowData.jzbsxxqk + '" />';}},
                        {field: 'sfcqfyhfyzmyw',title: 'sfcqfyhfyzmyw',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="sfcqfyhfyzmywRadio" id="sfcqfyhfyzmywRadio"' + rowIndex + 'value="' + rowData.sfcqfyhfyzmyw + '" />';}},
                        {field: 'cqfyhfyzmywxxqk',title: 'cqfyhfyzmywxxqk',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="cqfyhfyzmywxxqkRadio" id="cqfyhfyzmywxxqkRadio"' + rowIndex + 'value="' + rowData.cqfyhfyzmywxxqk + '" />';}},
                        {field: 'scbz',title: 'scbz',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="scbzRadio" id="scbzRadio"' + rowIndex + 'value="' + rowData.scbz + '" />';}},
                        {field: 'state',title: 'state',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="stateRadio" id="stateRadio"' + rowIndex + 'value="' + rowData.state + '" />';}},
                        {field: 'operator',title: 'operator',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="operatorRadio" id="operatorRadio"' + rowIndex + 'value="' + rowData.operator + '" />';}},
                        {field: 'createtime',title: 'createtime',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="createtimeRadio" id="createtimeRadio"' + rowIndex + 'value="' + rowData.createtime + '" />';}},
                        {field: 'fzdsl',title: 'fzdsl',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fzdslRadio" id="fzdslRadio"' + rowIndex + 'value="' + rowData.fzdsl + '" />';}},
                        {field: 'fzdbh',title: 'fzdbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="fzdbhRadio" id="fzdbhRadio"' + rowIndex + 'value="' + rowData.fzdbh + '" />';}},
                        {field: 'djwpsl',title: 'djwpsl',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="djwpslRadio" id="djwpslRadio"' + rowIndex + 'value="' + rowData.djwpsl + '" />';}},
                        {field: 'djwpbh',title: 'djwpbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="djwpbhRadio" id="djwpbhRadio"' + rowIndex + 'value="' + rowData.djwpbh + '" />';}},
                        {field: 'xh',title: 'xh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="xhRadio" id="xhRadio"' + rowIndex + 'value="' + rowData.xh + '" />';}},
                        {field: 'tz',title: 'tz',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="tzRadio" id="tzRadio"' + rowIndex + 'value="' + rowData.tz + '" />';}},
                        {field: 'ggys',title: 'ggys',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="ggysRadio" id="ggysRadio"' + rowIndex + 'value="' + rowData.ggys + '" />';}},
                        {field: 'ph',title: 'ph',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="phRadio" id="phRadio"' + rowIndex + 'value="' + rowData.ph + '" />';}},
                        {field: 'wpbh',title: 'wpbh',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="wpbhRadio" id="wpbhRadio"' + rowIndex + 'value="' + rowData.wpbh + '" />';}},
                        {field: 'jsr',title: 'jsr',formatter: function(value, rowData, rowIndex){return '<input type="radio" name="jsrRadio" id="jsrRadio"' + rowIndex + 'value="' + rowData.jsr + '" />';}},
                        ],
                    detailFormatter:function(index,rowData){
                        return ;
                    },
                    onClickRow:function(rowIndex, rowData){
                        if(id!=rowData.id){
                            $("input[name='wpjsRadio']")[rowIndex].checked = true;
                            $('#'+wpjsId).datagrid("selectRow", rowIndex);
                            id=rowData.id;
                        }else if(id==rowData.id){
                            $('#'+wpjsId).datagrid("unselectRow",rowIndex);
                            $("input[name='wpjsRadio']")[rowIndex].checked = false;
                            id="";
                        }
                    },
                    //双击事件
                    onDblClickRow:function(rowIndex, rowData){
                        $("input[name='wpjsRadio']")[rowIndex].checked = true;
                        $('#'+wpjsId).datagrid("selectRow", rowIndex);
                        id=rowData.id;
                        var jbxx = $('#jbxxId').datagrid('getSelected');
                        wpjsForm.show(jbxx,rowData,refreshTable);

                    },

                });
                $('#'+wpjsId).datagrid('resize',{
                    height:($(window).height() -320)
                });

            }
            var findWpjs=function(){
                var val = $("#jqjsTree").tree('getSelected');
                var s_rybh = $("#s_rybh").textbox('getValue');
                var s_xm = $("#s_xm").textbox('getValue');
                //人员状态,单选框
                var opts = $('#'+ryjbxxId).datagrid("options");
                opts.url = "/jls_jbxx/jbxxList";
                $('#'+ryjbxxId).datagrid('clearSelections');
                $('#'+ryjbxxId).datagrid('load',{
                	'xm':s_xm,
                    'rybh':s_rybh,
                });
            }
            var initJsTree=function(){
                kss.initJsTree("jqjsTree","jbxxId",{});
            }
            var bindAction=function(){
                $("#wpjs_search").on("click",function(){
                    findWpjs();
                });
                $("#wpjs_add").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    if(ryjbxx){
                        wpjsForm.show(ryjbxx,{},refreshTable);
                    }else{
                        $.messager.alert("提示","请选择要新增的记录!","info");
                    }
                });
                $("#wpjs_update").on("click",function(){
                    var ryjbxx=$("#"+ryjbxxId).datagrid('getSelected');
                    var wpjs=$("#"+wpjsId).datagrid('getSelected');
                    if(ryjbxx&&bjjl){
                        wpjsForm.show(ryjbxxwpjs,refreshTable,{});
                        $('#rybhId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#ryxmId').next().find('input[type=text]').css('background-color','#ebebe4');
                        $('#jshId').next().find('input[type=text]').css('background-color','#ebebe4');
                    }else{
                        $.messager.alert("提示","请选择要修改的记录!","info");
                    }
                });

                $(window).keydown(function(event) {
                    if (event.keyCode == 13) {
                        findwpjs();
                    }
                });
                comonts.ShowHide(jbxx,tmp);
                comonts.ShowHide(wpjs,tmpWpjs);
                $("#wpjs_print").on("click",function(){
                    var label="jls_wpjs";
                    var name="jls_wpjs";
                    var rybh=$("#"+ryjbxxId).datagrid('getSelected').rybh;
                    var url=comonts.getReportUrl(true,label,name,'rybh%3d'+rybh);
                    console.info(url);
                    addTab("Wpjs",url);
                });

            }
            var refreshTable=function(data){
                $('#'+wpjsId).datagrid('reload',{rybh:$('#'+ryjbxxId).datagrid('getSelected').rybh});
            }


            var initView=function(){
                tableInit();
                bindAction();
                initJsTree();

            }


            initView();
        });
